using System.Text.RegularExpressions;

namespace Chaotic.DataBase.DBAccessLibrary.Common;

public static class StringEx
{
	private const string filterPattern = "'.*?'";

	private const string SqlFilterKeyword = "_&&__&*&*";

	public static IEnumerable<string> ToFilterKeyword(this string content, string keyword)
	{
		if (Regex.IsMatch(content, "'.*?'"))
		{
			foreach (Match item in Regex.Matches(content, "'.*?'"))
			{
				if (item.Value.IndexOf(keyword, StringComparison.Ordinal) > 0)
				{
					string newValue = item.Value.Replace(keyword, "_&&__&*&*");
					content = content.Replace(item.Value, newValue);
				}
			}
		}
		List<string> list = new List<string>();
		string[] array = content.Split([keyword], StringSplitOptions.RemoveEmptyEntries);
		foreach (string text in array)
		{
			list.Add(text.Trim().Replace("_&&__&*&*", keyword));
		}
		return list;
	}
}
